#ifndef CELLWIDGET_H
#define CELLWIDGET_H

#include <QtGui/QWidget>
#include "ui_cellwidget.h"

class CellWidget: public QWidget {
Q_OBJECT

public:
	CellWidget(int i, QWidget *parent = 0);
	~CellWidget();

private:
	CellWidget(QWidget *parent = 0);

public:
	enum Dirs {
		Free = 0, U = 1, R = 2, D = 4, L = 8, None = 16
	};
	enum Shadow {
		NoShadow,
		TopShadow,
		BottomShadow,
		LeftShadow,
		RightShadow,
		TopLeftShadow,
		TopRightShadow,
		BottomLeftShadow,
		BottomRightShadow
	};
	enum {
		RotationTimeout = 18,
		RotationStep = 15,
		BlinkTimeout = 18,
		BlinkStep = 10,
		BlinkWidth = 6
	};
	enum Command {
		RotationToLeft, RotationToRight, LockUnlock
	};

	static void setGameOver(bool b);

	static CellWidget * focused();
	static void setFocused(CellWidget *);

	static void initPixmaps();
	static QPixmap fadedPixmap(const QPixmap &);

public:
	void setShadow(Shadow s);
	int index() const;

	Dirs dirs() const;
	void setDirs(Dirs d);

	bool isConnected() const;
	void setConnected(bool b);

	void setRoot(bool b);
	void setLocked(bool b);
	bool isRotated() const;

	void start(Command command);

	void rotate(int a);

signals:
	void noRotation();
	void startRotation();
	void finishRotation();

protected:
	virtual void paintEvent(QPaintEvent *);
	virtual void mousePressEvent(QMouseEvent *);

	virtual void timerEvent(QTimerEvent *);

private:
	Ui::CellWidgetClass ui;

	typedef QMap<int, QPixmap *> PixmapMap;

	static PixmapMap connectedpixmap;
	static PixmapMap disconnectedpixmap;
	static PixmapMap shadowpixmap;

	static CellWidget * focusedCell;

	static bool gameOver;

	int iindex;
	int rotationStep;
	int rotationTimer;
	int rotationProgress;
	int focusTimer;
	int focusProgress;
	int blinkTimer;
	int blinkProgress;
	bool connected;
	bool changed;
	bool locked;
	bool root;
	Dirs ddirs;
	Shadow shadow;
	QPixmap pixmap;
};

#endif // CELLWIDGET_H
